package handler

import (
	"github.com/gin-gonic/gin"
	"path/filepath"
	"school/user-api/api/reponse"
	"school/user-api/pkg"
)

func Upload(c *gin.Context) {
	file, err := c.FormFile("image")
	if err != nil {
		return
	}
	if file.Size > 2*1024*1024 {
		reponse.Error(c, "文件大小不正确")
		return
	}
	ext := filepath.Ext(file.Filename)
	if ext != ".png" {
		reponse.Error(c, "文件格式不正确")
		return
	}
	upload, err := pkg.Upload(file)
	if err != nil {
		reponse.Error(c, "上传失败")
		return
	}
	reponse.Success(c, "上传成功", upload)
}
